package zhou.chs.p2_2;

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.text.Html;
import android.text.method.ScrollingMovementMethod;
import android.widget.TextView;

public class MainActivity extends AppCompatActivity {
    TextView lbtv;                 //声明TextView
    String strred = "<font color = '#FF0000'>";   //红色
    String strblue = "<font color = '#0000FF'>";  //蓝色
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        lbtv = (TextView) findViewById(R.id.idtv);     //得到TextView对象的引用
        lbtv.setMovementMethod(ScrollingMovementMethod.getInstance());  //设定文本可滚动
        String txp="";
        for(int i=1;i<=12;i++){   //显示12行信息
            //前4行默认颜色：黑色
            if(i<4) txp= txp + "第" + i + "行：Hello World!" + "<br/>";
            //中间4行颜色：蓝色
            if((i>=4)&&(i<8)) txp= txp + strblue + "第" + i + "行：Hello World!" + "</font>" + "<br/>";
            //后4行颜色：红色
            if(i>=8) txp= txp + strred + "第" + i + "行：Hello World!" + "</font>" + "<br/>";
        }
        lbtv.setText(Html.fromHtml(txp));
    }
}
